<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">认证批次：</label>
                            <div class="col-sm-8">
                                <select id="cbatchId" name="cbatchId" class="form-control">
                                    <option value="">请选择</option>
                                    <option th:each="item : ${certificationBatch}"  th:value="${item.id}" th:text="${item.certificateName}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">考点：</label>
                            <div class="col-sm-8" id="orgIdDiv">
                                <!--<select id="orgId" name="orgId" class="form-control">-->
                                <!--</select>-->
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">考生姓名：</label>
                            <div class="col-sm-8">
                                <input id="selectPage" name="name" placeholder="输入姓名搜索" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script>
    $().ready(function() {
        validateRule();
    });

    $.validator.setDefaults({
        submitHandler : function() {
            save();
        }
    });
    //分页下拉框
    $("#cbatchId").change(function () {
        $.ajax({
            url: '/jzweb/stuSignUp/distributionOrgId',
            data :{cbatchId:$(this).val(),name:''} ,
            success: function (r) {
                var list ='<select id="orgId" name="orgId" class="form-control">';
                if(r.data.length==0){
                    list+='<option value="">暂无数据</option>';
                }else{
                    for(var p in r.data){
                        list+='<option value="'+r.data[p].id+'">'+r.data[p].name+'</option>';
                    }
                }
                list+='</select>';
                $("#orgIdDiv").html(list);
                console.log(r)
            }
        })
    })
    $('#selectPage').selectPage({
        showField : 'idNumber',
        keyField : 'id',
        data :'/jzweb/stuSignUp/distributionSecond',
        params : function(){
            return {'cbatchId':$('#cbatchId').val(),number:2,current:1};
        },
        searchField:'name',
        // pageSize:15,
        multiple:true,
        //格式化显示项目，提供源数据进行使用
        formatItem : function(data){
            return data.name + '(' + data.idNumber + ',' + data.orgName + ')';
        },
        eAjaxSuccess : function(d){
            console.log("d",d)
            var result;
            if(d) result = d.data;
            else result = undefined;
            return result;
        }
    });

    function save() {
        $.ajax({
            cache : true,
            type : "POST",
            url : "/jzweb/stuSignUp/distributionSave",
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });
    }
    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules : {
                name : {
                    required : true
                }
            },
            messages : {
                name : {
                    required : icon + "请输入"
                }
            }
        })
    }
</script>
</body>
</html>
